/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Dato;

import Utilitarios.Conexion;
import java.io.*;
import java.sql.*;
import java.util.ArrayList;
import javax.swing.*;
import javax.swing.table.*;

/**
 *
 * @author Omar Heráclides
 */
public class DPermiso {

    static ResultSet rs = null;
    static Statement st = null;

    public static ResultSet Select(String query) throws SQLException {

        Conexion conex = new Conexion();
        st = conex.ObtenerConexion();
        rs = st.executeQuery(query);
        return rs;
    }

    public static void Insert(String query) throws SQLException {

        Conexion conex = new Conexion();
        st = conex.ObtenerConexion();
        st.execute(query);
        st.close();
    }

    public static void UpDate(String query) throws SQLException {

        Conexion conex = new Conexion();
        st = conex.ObtenerConexion();
        st.execute(query);
        st.close();
    }

    public String ObtenerPermiso(String name) throws SQLException {
        String comando;
        comando = "Select  idpermiso from permiso where ventana='" + name + "'";;
        String num = "";
        ResultSet rs = Select(comando);
        while (rs.next()) {
            num = rs.getString(1);
        }

        System.out.println("idPermiso=" + num);
        return num;
    }

    public void InsertRolxPermmiso(String idr, String idp) throws SQLException {

        String comando;
        comando = "insert INTO rolxpermiso (idrol,idpermiso) values ";
        comando = comando + "('" + idr.trim() + "','" + idp.trim() + "')";
        JOptionPane.showMessageDialog(null, comando, "Información", JOptionPane.INFORMATION_MESSAGE);
        Insert(comando);
    }

    public String ObtenerPermisoConIDPermiso(String get) throws SQLException {
        String comando;
        System.out.println("idPermiso-" + get + "-");
        comando = "Select  ventana from permiso where idpermiso='" + get.trim() + "'";;
        String num = "";
        ResultSet rs = Select(comando);
        while (rs.next()) {
            num = rs.getString(1);
        }

        System.out.println("ventana=" + num);
        return num;
    }

    public void ModificarRolxPermmiso(String idRol, String idPermiso) throws SQLException {
        
        this.InsertRolxPermmiso(idRol, idPermiso);

    }
    public void DeletePermisosxRol(String idRol) throws SQLException {
        String comando;
        System.out.println("idPermiso-" + idRol + "--------------------Dataaa");
        comando = "Delete from rolxpermiso WHERE idrol=" + idRol + "";
        UpDate(comando);
    
    }
}
